<?php
if (!defined('baseinfo')) {
    exitdata();
}





if(count($data['formadd'])){ 
?>

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>
<script src="<?=baseinfo?>/js/vendor/gmap3.js"></script>
<script src="<?=baseinfo?>/js/vendor/binaryajax.js"></script>
<script src="<?=baseinfo?>/js/vendor/exif.js"></script>
<script src="<?=baseinfo?>/js/vendor/canvasResize.js"></script>
<script src="<?=baseinfo?>/js/vendor/jquery.Jcrop.min.js"></script>
<script src="<?=baseinfo?>/js/vendor/jquery.iuploader-1.0.js"></script>
<script src="<?=baseinfo?>/js/vendor/jsuri-1.1.1.js"></script>
<link href="//vjs.zencdn.net/4.7/video-js.css" rel="stylesheet">
<script src="//vjs.zencdn.net/4.7/video.js"></script>



<link rel="stylesheet" href="<?=baseinfo?>/js/vendor/minified/themes/default.min.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?=baseinfo?>/css2/addfeature2.css" type="text/css" media="all" />
<script src="<?=baseinfo?>/js/vendor/minified/jquery.sceditor.bbcode.min.js"></script>

<script src="<?=baseinfo?>/js/coreadd.js"></script>
<link rel="stylesheet" href="<?=baseinfo?>/css/vendor/jcrop/jquery.Jcrop.min.css" type="text/css" />
<? if(detectdevice()){?>
<script src="<?=baseinfo?>/js/vendor/jquery.ui.touch-punch.min.js"></script>
<?}?>
 <script>
 var dataform={};
 var datasaveform={};
 var rowdiv=1;
 var iscredit=0;
 <?if($data['product']['iscredit']=='1')
 {
 
     ?>
     
     iscredit=1;
     
     <?
 
 
 }?>
  var creditset=0;
 <?if($data['product']['credit']!='0'&&$data['product']['credit'])
 {
 
     ?>
     
     creditset=<?=$data['product']['credit']?>;
     
     <?
 
 
 }?>
//$.unblockUI();
//console.log('test');
 
 function saveaddfeaturedata()
 {
    datasaveform={};
    var errorform={};
    var rowerror=0;
    
    if(loadimagewidthfinish==0)
    {
    errorform[rowerror]={'code':'22','msg':'Please Wait For Upload File'};
    rowerror++;
    }
    
    //alert('Handler for .submit() called.');
    if($('input[name="title"]').val().trim()=="")
    {
    errorform[rowerror]={'code':'19','msg':'Requied Title'};
    rowerror++;
    }
    
    //if($('textarea[name="description"]').val()=="")
//    {
//    errorform[rowerror]={'code':'20','msg':'Requied Description'};
//    rowerror++;
//    }
    
    
    if( ($('input[name="tagsystem[]"]:checked').length==0)&&$('input[name="taguser[]"]').val()=="")
    {
    
    errorform[rowerror]={'code':'21','msg':'Requied Tag'};
    rowerror++;
    }
    
    

    
    if($('#lastaddform input[name="imgmid[]"]').val()==""||$('#lastaddform input[name="simgmid[]"]').val()=="")
    {
    errorform[rowerror]={'code':'22','msg':'Requied Thumbnail'};
    rowerror++;
    
    }
   // console.log(errorform);
    
    if(rowerror>0)
    {
    
    alertwrongbox(errorform);
    }else
    {
    datasaveform['title']=$('input[name="title"]').val();
    datasaveform['description']=$('textarea[name="description"]').val();
    datasaveform['fid']=$('input[name="fid"]').val();
    datasaveform['productid']=$('input[name="productid"]').val();
    datasaveform['code']=$('input[name="code"]').val();
    datasaveform['ispoi']=$('input[name="ispoi"]').val();
    datasaveform['infoid']=$('input[name="infoid"]').val();
    datasaveform['imgmid']=$('#lastaddform input[name="imgmid[]"]').val();
    datasaveform['simgmid']=$('#lastaddform input[name="simgmid[]"]').val();
    datasaveform['status']=$('input[name="status[]"]:checked').val();
    
    if($('input[name="datepostuser[]"]').length)
    {
    
    datasaveform['createdate']=$('input[name="datepostuser[]"]').val();
  
    }
    
    
    
    var rowtagsystem=0;
    datasaveform['tagsystem']=[];
    $.each($('input[name="tagsystem[]"]:checked'), function() {
    
    datasaveform['tagsystem'][rowtagsystem]=$(this).val();
    rowtagsystem++;
    
    });

    
    
    datasaveform['taguser']=$('input[name="taguser[]"]').val();
    
    datasaveform['plugin']={};
    
    var rowplugin=0;
//    $.each($('#firstaddform div.featureclass'), function() {
//        
//        if(typeof($(this).find('input[name="plugname[]"]').val()) != "undefined")
//        {
        //console.log($(this).find('input[name="plugname[]"]').val());
//        
//        eval("datasaveform['plugin'][rowplugin]=saveform"+$(this).find('input[name="plugname[]"]').val()+"('"+$(this).attr("id")+"','"+$(this).find('input[name="plugid[]"]').val()+"');");
//        if(datasaveform['plugin'][rowplugin]['code']&&datasaveform['plugin'][rowplugin]['error'])
//        {
//        errorform[rowerror]=datasaveform['plugin'][rowplugin];
//        rowerror++;
//        }
//        
//        
//        rowplugin++;
//        
//        }
//    
//    });
    
    
        $.each($('div.featureclass'), function() {
        
        if(typeof($(this).find('input[name="plugname[]"]').val()) != "undefined")
        {
        
        eval("datasaveform['plugin'][rowplugin]=saveform"+$(this).find('input[name="plugname[]"]').val()+"('"+$(this).attr("id")+"','"+$(this).find('input[name="plugid[]"]').val()+"');");
        if(datasaveform['plugin'][rowplugin]['code']&&datasaveform['plugin'][rowplugin]['error'])
        {
        errorform[rowerror]=datasaveform['plugin'][rowplugin];
        rowerror++;
        }
        
        rowplugin++;
        
        }
    
    });
    
    
    if(rowerror>0)
    {
    //console.log(errorform);
    alertwrongbox(errorform);
    
    }else
    {
    
     loaddata();
     $.post(serviceinfo+'saveproduct', datasaveform, function(data) { 
     loadclosedata();
        if(data.error.response)
         {
          //alertbox(data.error.error);
          boxmsgdata(data.error.error);
         
         }else
         {
            location.href= baseinfo+'/'+data.data.link+'/'+data.data.productid
         }
     
     
     });
    
    
    }
    
    
    
    
    
    
    
    }

    
    
    
    
    
    
    
    return false;
    
 }
 

<?
$bookdata=0;
$uptime=0;
foreach($data['formadd'] as $keyform=> $valueform)
{
if($keyform=='bookdata')
{
$bookdata=1;
}

if($keyform=='uptime')
{
$uptime=1;
}
 ?>


 dataform['<?=$keyform?>']='<?=$valueform;?>';




<?
}
?>

 $( document ).ready(function() { 
 
 
 diskeyborad=1;
 <?
 
if(count($data['default']))
{
foreach($data['default'] as $keyform=> $valueform)
{
 if($valueform==1)
 {
  $onclick='addform'.$keyform.'();';
 }else 
 {
 $onclick="var config=".$valueform.';';
$onclick.='addform'.$keyform.'(config);';
 }
 
 if(count($data['product'])==0&&$data['alwayshow'][$keyform])
 {
 if($data['alwayshow'][$keyform]==1)
 {
 echo $onclick;
 }
 
 }
 
 
 if(isset($data['icon'][$keyform]))
 {
 echo "var iconcount".$keyform."=".$data['icon'][$keyform].";";
 $namekey=ucfirst($keyform);
 if($keyform=='imagewidth')
 {
 $namekey='Image';
 }else if($keyform=='vdo')
 {
 $namekey='Youtube';
 $data['iconname'][$keyform]='icoVdoYtEditTl';
 }
 else if($keyform=='vdoupload')
 {
 $namekey='Vdo Upload';
// $data['iconname'][$keyform]='icoVdoYtEditTl';
 }
  else if($keyform=='reservationregister')
 {
 $namekey='Reservation';
// $data['iconname'][$keyform]='icoVdoYtEditTl';
 }else if($keyform=='reservationregistercanon')
 {
 $namekey='C-Reservation';
// $data['iconname'][$keyform]='icoVdoYtEditTl';
 }
 

 
 echo "var icon".$keyform."='<div class=\"icoEditTl\" id=\"button$keyform\"><span class=\"ico ".$data['iconname'][$keyform]." \"></span><span>".$namekey."</span></div>';"; 
 
 echo  '$("#iconset").append(icon'.$keyform.');';
 
 echo  '$("#button'.$keyform.'").click(function() {
            if(iconcount'.$keyform.'==0||iconcount'.$keyform.'<2)
            {
            if(iconcount'.$keyform.'==1)
            {
            
                  iconcount'.$keyform.'++;
            }
            
            '.$onclick.'
            boxmsgdata(\'Success\');
            
            if(toggledata)
            {
            $(\'#addform .featureclass\').removeClass(\'repoSize\');
            }else
            {
            $(\'#addform .featureclass\').addClass(\'repoSize\');
            
            }
            
            }else
            {
            boxmsgdata("1 row click");
            
            }
            
            });';

            
 }

 
 
}
}

if(count($data['product']['plugins']))
{
foreach($data['product']['plugins'] as $valueeditproduct)
{

        $valuedefault=$data['default'][$valueeditproduct['plugname']];
        
            echo "var rowdatanow=".json_encode($valueeditproduct).';';  
        if($valuedefault==1)
        {
       echo 'editform'.$valueeditproduct['plugname'].'(rowdatanow);'; 
        } else 
        {
           echo "var config=".$valueform.';';  
           echo 'editform'.$valueeditproduct['plugname'].'(config,rowdatanow);'; 
        }
        
        if($valueeditproduct['plugname']=='bookdata')
        {
         $bookdata=0;
        }

}
          $rowproductset=$data['product'];
          unset($rowproductset['plugins']);
          echo "var rowdatanow=".json_encode($rowproductset).';';  
          echo "editformthumbnail(rowdatanow);";
           
    if($bookdata)
    {
      echo 'addformbookdata();';
    
    }
    
    
    if($uptime)
    {
      list($d,$t)=explode(' ',$data['product']['createdate']);
      list($y,$m,$d)=explode('-',$d);
      list($h,$i,$s)=explode(':',$t);
      
      
      echo 'editformuptime("'.$d.'/'.$m.'/'.$y.' '.$h.':'.$i.'");';
    
    }
    
    
    

}
?> 
<? //if($data['nowfeature']['reposize']==1){?>
$("#iconset").append('<div id="repoSize" class="icoEditTl wrpRePosEditTl clBd2"><span class="ico icoRePosEditTl"></span><span>Re-Position<\/span></div>');
<?// }?>
$("#repoSize").click(function() {
togglesort()  ;
});
     
 //$( "#addform" ).sortable();    
 
// $('#formaddfeature').submit(function() 

// 
// );
 
 
$('#btnsubmit').click(function() {

//$('#formaddfeature').submit();
saveaddfeaturedata();

});
 
 
 });

</script> 
<? 


}

?>

<?if(count($data['cssadd'])){

        foreach($data['cssadd'] as $valuecss)
        {
       if(is_array($valuecss))
       {
       foreach($valuecss as $valuecss2)
       {
       
      // echo '<script type="text/javascript" src="'.$valuejs2.'"></script>';   
       echo '<link type="text/css" rel="stylesheet" href="'.$valuecss2.'">';
       
       }
       
       }else
       {
       
       echo '<link type="text/css" rel="stylesheet" href="'.$valuecss2.'">';   
       }
        
        }
        }
    ?>


<?if(count($data['jsadd'])){

        foreach($data['jsadd'] as $valuejs)
        {
       if(is_array($valuejs))
       {
       foreach($valuejs as $valuejs2)
       {
       
       echo '<script type="text/javascript" src="'.$valuejs2.'"></script>';   
       
       }
       
       }else
       {
       
       echo '<script type="text/javascript" src="'.$valuejs.'"></script>';    
       }
        
        }
        }
    ?>





